package com.guoguo.service.impl;

import com.github.pagehelper.PageHelper;
import com.guoguo.base.PageBean;
import com.guoguo.entity.SysImg;
import com.guoguo.entity.vo.SysImgVO;
import com.guoguo.mapper.SysImgMapper;
import com.guoguo.service.SysImgService;
import com.guoguo.utils.AliOssUtils;
import com.guoguo.utils.aliOss.AliOssImageConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/28.
 */
@Service
public class SysImgServiceImpl implements SysImgService {

    @Autowired
    private SysImgMapper sysImgMapper;

    @Override
    public PageBean<SysImgVO> sysImgList(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<SysImgVO> sysImgVOs = sysImgMapper.sysImgList();
        return new PageBean<SysImgVO>(sysImgVOs);

    }

    @Override
    public int updateSysImg(SysImgVO sysImgVO) {
        return sysImgMapper.updateSysImg(sysImgVO);

    }

    @Override
    public int insert(SysImgVO sysImgVO) {
        return sysImgMapper.insert(sysImgVO);

    }

    @Override
    public int deleteById(String sysId) {
        return sysImgMapper.deleteById(sysId);

    }

    @Override
    public SysImgVO selectSysImgById(String sysId) {
        return sysImgMapper.selectSysImgById(sysId);

    }

    @Override
    public SysImg selectByPrimaryKey(String sysId) {
        SysImg sysImg = sysImgMapper.selectByPrimaryKey(sysId);
        return sysImg;
    }

    @Override
    public SysImg addSysImg(String sysId, int sysImgType, Boolean isShow, String args1, String sysImgUrl, Date createTime, Date updateTime) {
        Map<String, Object> data = new HashMap<>();
        SysImg sysImg = sysImgMapper.selectByPrimaryKey(sysId);
        if (sysImg == null) {
            sysImg = new SysImg(sysId, sysImgType, isShow, args1, sysImgUrl, createTime, updateTime);
            int num = sysImgMapper.insertSelective(sysImg);
            return sysImg;
        } else {

            Date now = new Date();
            sysImg.setSysImgType(sysImgType);
            sysImg.setShow(isShow);
            sysImg.setArgs1(args1);
            sysImg.setSysImgUrl(sysImgUrl);
            sysImg.setCreateTime(now);
            int num = sysImgMapper.updateByPrimaryKeySelective(sysImg);
            return sysImg;
        }

    }
}
